﻿Imports DTO
Imports System.Data.SqlClient


Public Class CTinhTrangPhieuMuonDAO
    Public Function LayDanhSachTinhTrangPhieuMuon() As List(Of CTinhTrangPhieuMuonDTO)
        Using cn As SqlConnection = CDataProvider.Connect()
            Dim cm As New SqlCommand("uspLoadTinhTrangPhieuMuon", cn)
            cm.CommandType = CommandType.StoredProcedure
            Dim listttpm As New List(Of CTinhTrangPhieuMuonDTO)()
            Using reader As IDataReader = cm.ExecuteReader(CommandBehavior.CloseConnection)
                While reader.Read()
                    listttpm.Add(New CTinhTrangPhieuMuonDTO(reader))
                End While
            End Using
            Return listttpm
        End Using
    End Function

    Public Function ThemTinhTrangPhieuMuon(ByVal tentinhtrangphieumuon As String) As Integer
        Using cn As SqlConnection = CDataProvider.Connect()
            Dim cm As New SqlCommand("usp_ThemTinhTrangPhieuMuon", cn)
            cm.CommandType = CommandType.StoredProcedure
            Dim para As New SqlParameter("@tentinhtrangphieumuon", tentinhtrangphieumuon)
            cm.Parameters.Add(para)
            Dim parakq As New SqlParameter("@kt", 0)
            parakq.Direction = ParameterDirection.Output
            cm.Parameters.Add(parakq)
            cm.ExecuteNonQuery()
            Dim kq As Integer = Integer.Parse(cm.Parameters("@kt").Value.ToString())
            cn.Close()
            Return kq
        End Using
    End Function


    Public Function CapNhatTinhTrangPhieuMuon(ByVal tinhtrangphieumuon As CTinhTrangPhieuMuonDTO) As Integer
        Using cn As SqlConnection = CDataProvider.Connect()
            Dim cm As New SqlCommand("usp_CapNhatTinhTrangPhieuMuon", cn)
            cm.CommandType = CommandType.StoredProcedure
            Dim para As New SqlParameter("@matinhtrangphieumuon", tinhtrangphieumuon.Ma)
            cm.Parameters.Add(para)
            para = New SqlParameter("@tentinhtrangphieumuon", tinhtrangphieumuon.Ten)
            cm.Parameters.Add(para)
            Dim parakt As New SqlParameter("@kt", 0)
            parakt.Direction = ParameterDirection.Output
            cm.Parameters.Add(parakt)

            cm.ExecuteNonQuery()
            Dim kq As Integer = Integer.Parse(cm.Parameters("@kt").Value.ToString())
            cn.Close()
            Return kq
        End Using
    End Function

End Class
